package com.tico.editor;

import com.tico.editor.editors.kafkaThread.KafkaChangeToipcThread;
import com.tico.editor.editors.kafkaThread.KafkaThread;
import com.tico.editor.editors.kafkaThread.ListenKafkaThread;
import com.tico.editor.editors.kafkaThread.TaskThread;
import com.tico.editor.editors.service.HttpEditorService;
import com.tico.editor.editors.service.KafkaService;
import com.tico.editor.editors.service.KafkaTopicService;
import com.tico.editor.editors.service.TaskScheduledService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Timer;
import java.util.TimerTask;

@Slf4j
@Component
public class SpringListen implements ApplicationRunner {
    @Autowired
    private TaskScheduledService scheduledService;
    @Autowired
    private HttpEditorService httpEditorService;
    @Autowired
    private KafkaService kafkaService;
    @Autowired
    private KafkaTopicService kafkaTopicService;
	@Override
	public void run(ApplicationArguments applicationArguments) throws Exception {
		try {
            //动态监听任务状态
            new Thread(new TaskThread(kafkaService,kafkaTopicService,scheduledService,httpEditorService)).start();
            //动态监听kafka改变
            new Thread(new KafkaThread(kafkaService,kafkaTopicService,httpEditorService)).start();
            //启动默认侦听topic
            new Thread(new ListenKafkaThread(scheduledService,httpEditorService)).start();
            //动态监听kafkaTopic改变
            new Thread(new KafkaChangeToipcThread(kafkaService,kafkaTopicService,httpEditorService)).start();
		}catch (Exception e){
			log.error("启动异常",e);
			e.printStackTrace();
		}

	}
}